create database test
 create table sinhvien
(
	masv nvarchar(10),
	hoten nvarchar(50),
	diem float
);


create procedure usp_Tran3
as
begin tran
	set tran isolation level  serializable
	insert into SinhVien (MaSV) values ('0912003')
	waitfor delay '0:0:05'
	
	if (exists (select * 
				from SinhVien
				where diem is null))
		rollback tran
		
	select * from SinhVien
	waitfor delay '0:0:05'
	
	select * from SinhVien
commit tran


create procedure usp_Tran2
as
begin tran
	declare @masv char (10)
	set @masv = (select top(1) MaSV
				from SinhVien
				order by MaSV desc)
	update SinhVien
	set diem = 5.3
	where MaSV = @masv
	waitfor delay '0:0:05'
	
	insert into SinhVien (MaSV)
	values ('0912004')
commit tran


exec usp_Tran3
exec usp_Tran2
